<template>
  <div class="card" v-for="(video, index) in videoData" :key="video.videoId">
    <div class="card-header">
      <span :class="video.status === 1 ? 'free' : 'paid'">
        {{ video.status === 1 ? "免费公开课(固定)" : "付费课程" }}
      </span>
    </div>
    <div class="card-body">
      <img :src="video.videoImg" alt="video cover" class="video-img" />
      <div class="video-info">
        <h3 class="video-title">{{ truncate(video.videoName, 10) }}</h3>
        <p class="video-remake">{{ video.videoRemake }}</p>
        <p class="teacher-name">{{ video.teacher.teacherName }}</p>
        <button class="learn-button">我要学习</button>
      </div>
    </div>
  </div>
</template>

<script>
import videoData from "@/js/testData/videoData.js";

export default {
  data() {
    return {
      videoData
    };
  },
  methods: {
    truncate(text, length) {
      return text.length > length ? text.slice(0, length) + "..." : text;
    }
  }
};
</script>

<style scoped>
.card {
  width: 300px;
  border-radius: 10px;
  background-color: #f5f8ff;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
  margin: 10px;
  overflow: hidden;
}

.card-header {
  padding: 10px;
  font-weight: bold;
  font-size: 14px;
  color: #333;
}

.free {
  color: #007bff;
}

.paid {
  color: #ff4500;
}

.card-body {
  display: flex;
  padding: 10px;
  align-items: center;
}

.video-img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  margin-right: 10px;
  object-fit: cover;
}

.video-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.video-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.video-remake {
  font-size: 12px;
  color: #666;
  margin: 5px 0;
}

.teacher-name {
  font-size: 12px;
  color: #333;
}

.learn-button {
  padding: 5px 10px;
  background-color: #007bff;
  color: white;
  font-size: 12px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  margin-top: 10px;
}
.learn-button:hover {
  background-color: #0056b3;
}
</style>
